//
//  AlertUtils.m
//  advideo
//
//  Created by mokai on 14-7-26.
//  Copyright (c) 2014年 cloudyoo. All rights reserved.
//

#import "AlertUtils.h"

@implementation AlertUtils

+ (void)showAlert:(NSString*)message{
    [self showAlert:nil message:message cancelButtonTitle:@"确定"];
}


+ (void)showAlert:(NSString*)title message:(NSString*)msg cancelButtonTitle:(NSString*)cancelButtonTitle
{
    [self showAlert:title message:msg cancelButtonTitle:cancelButtonTitle cancelHandler:nil];
}

+ (void)showAlert:(NSString*)title message:(NSString*)msg cancelButtonTitle:(NSString*)cancelButtonTitle cancelHandler:(AlertUtilsBlock) chandler
{
    [self showAlert:title message:msg cancelButtonTitle:cancelButtonTitle cancelHandler:chandler otherButtonTitle:nil otherHandler:nil];
}


+ (void)showAlert:(NSString *)title message:(NSString *)message
cancelButtonTitle:(NSString *)cancelButtonTitle cancelHandler:(AlertUtilsBlock) chandler
otherButtonTitle:(NSString *)otherButtonTitle  otherHandler:(AlertUtilsBlock) ohandler{
  
    SIAlertView *alert = [[SIAlertView alloc] initWithTitle:title
                                                 andMessage:message];
    [alert setTransitionStyle:SIAlertViewTransitionStyleSlideFromTop];
    [alert addButtonWithTitle:cancelButtonTitle type:SIAlertViewButtonTypeDefault handler:^(SIAlertView *alert){
        [alert dismissAnimated:YES];
        if(chandler)chandler();
    }];
    if (otherButtonTitle) {
        [alert addButtonWithTitle:otherButtonTitle type:SIAlertViewButtonTypeDefault handler:^(SIAlertView *alert){
            [alert dismissAnimated:YES];
            if(ohandler)ohandler();
        }];
    }
    [alert show];
}



+(void)showToastWithMessage:(NSString *)message{
    UIViewController *ctr = [UIUtils currentViewController];
    [self showToastWithMessage:message inView:ctr.view hideAfterDelay:1 beIndeter:NO];
}

+(void)showToastWithMessage:(NSString *)message inView:(UIView *)view{
    [self showToastWithMessage:message inView:view hideAfterDelay:1 beIndeter:NO];
}

+(void)showToastWithMessage:(NSString *)message inView:(UIView *)view hideAfterDelay:(NSTimeInterval)delay beIndeter:(BOOL)indeter{
    [self hideToastInView:view];
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
	
	// Configure for text only and offset down
    if (indeter) {
        hud.mode = MBProgressHUDModeIndeterminate;
    }else{
        hud.mode = MBProgressHUDModeText;
    }

	hud.labelText = message;
    hud.labelFont = [UIFont fontWithName:@"BanglaSangamMN" size:15];
	hud.margin = 10.f;
    //	hud.yOffset = 150.f;
	hud.removeFromSuperViewOnHide = YES;
	if (delay > 0) {
        [hud hide:YES afterDelay:delay];
    }
}




+(void)hideToast{
    UIViewController *ctr = [UIUtils currentViewController];
    [MBProgressHUD hideAllHUDsForView:ctr.view animated:NO];
}

+(void)hideToastInView:(UIView *)view{
    [MBProgressHUD hideAllHUDsForView:view  animated:NO];
}



@end
